package tcc.model.dao;

import java.util.ArrayList;
import java.util.List;

import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.Transaction;

import tcc.model.entities.EdgeEntity;
import tcc.resources.HibernateUtil;

/**
 * Get information from the database on Edges table
 * @author Gabriel Pacheco
 *
 */
public class EdgeDao {
	@SuppressWarnings("unchecked")
	public List<EdgeEntity> getEdgeList() {
		Session session = HibernateUtil.getSessionfactory().openSession();
		Transaction transaction = null;
		List<EdgeEntity> edgeList = new ArrayList<EdgeEntity>();

		try{
			transaction = session.beginTransaction();
			edgeList = session.createQuery("FROM EdgeEntity").list();
			transaction.commit();
		}catch (HibernateException e) {
			System.out.println("Erro ao executar Select" + e.getMessage() );
			transaction.rollback();
			e.printStackTrace();
		}finally{
			session.close();
		}
		
		return edgeList;
	}
}